import 'package:flutter/material.dart';

class RadioPage extends StatefulWidget {
  const RadioPage({Key? key}) : super(key: key);

  @override
  _RadioPageState createState() => _RadioPageState();
}

class _RadioPageState extends State<RadioPage> {
  var _sex=1;
  bool _flag=true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Radio'),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child:Column(
          children: <Widget>[
            /*Row(
              children: [
                Text('男:'),
                Radio(
                  value: 1,
                  groupValue: this._sex,
                  onChanged: (int? v){
                    print(v);
                    setState(() {
                      this._sex=v!;
                    });
                  },
                ),
                SizedBox(width: 10,),
                Text('女:'),
                Radio(
                  value: 2,
                  groupValue: this._sex,
                  onChanged: (int? v){
                    print(v);
                    setState(() {
                      this._sex=v!;
                    });
                  },
                ),
              ],
            ),
            Row(
              children: [
                Text('${this._sex}'),
                Text(this._sex==1?'男':'女'),
              ],
            ),*/
            SizedBox(height: 40,),
            RadioListTile(
              value: 1,
              groupValue: this._sex,
              onChanged: (int? v){
                setState(() {
                  this._sex=v!;
                });
              },
              title: Text('标题1'),
              subtitle: Text('子标题1'),
              secondary: Icon(Icons.ac_unit),
              selected: this._sex==1,
            ),
            RadioListTile(
              value: 2,
              groupValue: this._sex,
              onChanged: (int? v){
                setState(() {
                  this._sex=v!;
                });
              },
              title: Text('标题2'),
              subtitle: Text('子标题2'),
              secondary: Image.network('https://www.itying.com/images/flutter/2.png'),
              selected: this._sex==2,
            ),
            SizedBox(height: 20,),
            Switch(
              value: this._flag,
              onChanged: (v){
                setState(() {
                  this._flag=v;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
